package com.lifei.controller;

import com.lifei.VO.ResultData;
import com.lifei.domain.Order;
import com.lifei.repository.OrderRepository;
import com.lifei.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/api")
public class SecKillResource {

    @Autowired
    private OrderRepository orderRepository;
    @Autowired
    private OrderService orderService;

    // 下单操作
    @GetMapping("/submit-order")
    public ResultData<Integer> submitOrder(){
        Integer res = orderService.submitOrder(1);
        return new ResultData<>(200,res > 0?"下单成功":"库存不足",res);
    }

    // 支付操作
    @GetMapping("/pay-order/{id}")
    public ResultData<Order> payOrder(@PathVariable Integer id) {
        return orderService.payOrder(id);
    }


    @GetMapping("/get-order")
    public List<Order> getOrder() {
        return orderRepository.findAll();
    }


}
